#声明要求的最小版本
cmake_minimum_required(VERSION 2.8)
#项目名称
PROJECT(SimpleTest)

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O2")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -Wall -O2")

#添加参与编译的子目录 我理解为：添加下一个CMakeLists.txt
#对于src适合使用AUX_SOURCE_DIRECTORY
#ADD_SUBDIRECTORY(ls1b_dtu_lib)

#添加头文件的查找目录 && 在编译参数"-l" ，指定搜索头文件的路径
INCLUDE_DIRECTORIES(
${PROJECT_SOURCE_DIR}/ 
#${PROJECT_SOURCE_DIR}/ls1b_dtu_lib/include
)


#添加需要链接的库文件目录
LINK_DIRECTORIES(
	#${PROJECT_SOURCE_DIR}/ls1b_dtu_lib
)

#4.source directory，源文件目录
AUX_SOURCE_DIRECTORY(i2c I2C_DIR_SRCS)
AUX_SOURCE_DIRECTORY(rtc RTC_DIR_SRCS)
AUX_SOURCE_DIRECTORY(spi SPI_DIR_SRCS)
AUX_SOURCE_DIRECTORY(pwm PWM_DIR_SRCS)
AUX_SOURCE_DIRECTORY(uart UART_DIR_SRCS)
AUX_SOURCE_DIRECTORY(can CAN_DIR_SRCS)

#指定生成目标
ADD_EXECUTABLE(i2c_test ${I2C_DIR_SRCS})
ADD_EXECUTABLE(rtc_test ${RTC_DIR_SRCS})
ADD_EXECUTABLE(spi_test ${SPI_DIR_SRCS})
ADD_EXECUTABLE(pwm_test ${PWM_DIR_SRCS})
ADD_EXECUTABLE(uart_test ${UART_DIR_SRCS})
ADD_EXECUTABLE(can_test ${CAN_DIR_SRCS})

#TARGET_LINK_LIBRARIES 用来链接 -l后的文件依赖
#TARGET_LINK_LIBRARIES(ls1b_dtu_lib_test ls1b_dtu)

#EXECUTABLE_OUTPUT_PATH && LIBRARY_OUTPUT_PATH用来指定二进制文件位置和库文件路径，这里不包括中间文件
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/out/bin)

# 安装main是可执行文件
INSTALL(TARGETS i2c_test rtc_test  RUNTIME DESTINATION bin)

### Testing 指令:make test#
ENABLE_TESTING()
ADD_TEST(NAME SimpleTest COMMAND i2c_test)

#增加客制化命令指令:make run#
ADD_CUSTOM_TARGET(run
	COMMAND rtc_test
	)
